package com.meisiabc.app.web.auth;

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by sunchangpeng
 */
@Slf4j
public abstract class AuthHandler {
    public static final String SECURITY_AUTH_KEY = "identity_token";
    protected String tokenName = SECURITY_AUTH_KEY;

    public boolean autoLogin(HttpServletRequest request) {
        String authToken = extractAuthToken(request);
        if (StringUtils.isBlank(authToken)) {
            return false;
        }
        return processAuthToken(authToken);
    }

    protected abstract boolean processAuthToken(String authToken);

    private String extractAuthToken(HttpServletRequest request) {
        return request.getHeader(tokenName);
    }
}
